package com.zyc.eduservice.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zyc.commonUtils.R;
import com.zyc.eduservice.entity.EduCourse;
import com.zyc.eduservice.entity.EduTeacher;
import com.zyc.eduservice.service.EduCourseService;
import com.zyc.eduservice.service.EduTeacherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author zyc
 * @create 2022-02-24-21:28
 */
@Api("用户端首页")
@RestController
@RequestMapping("/eduservice/index")
@CrossOrigin //解决跨域
public class IndexController {

    @Autowired
    private EduCourseService eduCourseService;

    @Autowired
    private EduTeacherService eduTeacherService;

    @ApiOperation(value = "用户端首页")
    @GetMapping("index")
    public R index() {
        //查询前八热门视频
        QueryWrapper<EduCourse> wrapper = new QueryWrapper<>();
        wrapper.orderByDesc("view_count");
        wrapper.last("limit 8");
        List<EduCourse> courseList = eduCourseService.list(wrapper);

        //查询前四名师
        QueryWrapper<EduTeacher> wrapper1 = new QueryWrapper<>();
        wrapper1.orderByDesc("sort");
        wrapper1.last("limit 4");
        List<EduTeacher> teacherList = eduTeacherService.list(wrapper1);

        return R.ok().data("courseList",courseList).data("teacherList",teacherList);
    }


}
